package com.qianyu.api.controller.back.tranmag;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianyu.core.entity.base.Result;
import com.qianyu.core.entity.bean.OrderPay;
import com.qianyu.core.entity.bean.PayWay;
import com.qianyu.core.entity.bean.WalletAccount;
import com.qianyu.core.entity.dto.OrderPayDto;
import com.qianyu.core.entity.dto.WalletAccountDto;
import com.qianyu.core.service.OrderPayService;
import com.qianyu.core.service.PayWayService;
import com.qianyu.core.service.WalletAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "后台管理-交易管理", description = "wangzhicheng")
@RestController
@RequestMapping("/api/orderPay")
@RequiredArgsConstructor
public class BackOrderPayController {

    private final OrderPayService orderPayService;

    private final PayWayService payWayService;

    private final WalletAccountService walletAccountService;

    /**
     * 充值记录
     */
    @PostMapping(value = "/pageOrderPay")
    @ApiOperation(value = "充值记录")
    Result<Page<OrderPay>> pageOrderPay(@RequestBody @Validated OrderPayDto.OrderPayPageDto dto) {
        return Result.success(orderPayService.pageOrderPay(dto, null));
    }

    /**
     * 后台审核充值订单
     */
    @PostMapping(value = "/audit")
    @ApiOperation(value = "后台审核充值订单")
    Result<String> checkPayOrder(@RequestBody @Validated OrderPayDto.OrderPayAuditDto dto) {
        orderPayService.checkPayOrder(dto);
        return Result.success();
    }


    /**
     * 查询支付方式
     */
    @GetMapping("/getPayWay")
    @ApiOperation(value = "查询支付方式")
    Result<List<PayWay>> getPayWay() {
        return Result.success(payWayService.getPayWay());
    }


    /**
     * 查询账户信息
     */
    @GetMapping("/getAccount")
    @ApiOperation(value = "查询账户信息")
    Result<WalletAccount> getAccount() {
        return Result.success(walletAccountService.getAccount());
    }


    /**
     * 新增账户信息
     */
    @PostMapping("/saveWalletAccount")
    @ApiOperation(value = "新增账户信息")
    Result<String> saveWalletAccount(@RequestBody @Validated WalletAccountDto.WalletAccountSaveDto dto) {
        walletAccountService.saveWalletAccount(dto);
        return Result.success();
    }

    /**
     * 编辑账户信息
     */
    @PostMapping("/editWalletAccount")
    @ApiOperation(value = "编辑账户信息")
    Result<String> editWalletAccount(@RequestBody @Validated WalletAccountDto.WalletAccountEditDto dto) {
        walletAccountService.editWalletAccount(dto);
        return Result.success();
    }
}
